import { Component, Input, OnDestroy, AfterViewInit } from '@angular/core';
 
@Component({
  selector: 'smscode',
  templateUrl: 'smscode.html'
})
export class SmscodeComponent implements AfterViewInit, OnDestroy {
 	// 秒数差
 	private second: number;
 	// 时间差
 	private _diff: number;
 
 	private get diff() {
  		return this._diff;
 	}
 
 	private set diff(val) {
  		this._diff = Math.floor(val / 1000);
  		this.second = (this._diff % 3600) % 60;
 	}
 
 	// 定时器
 	private timer;
 
 	// 每一秒更新时间差
 	ngAfterViewInit() {
  		this.timer = setInterval(() => {
   			// this.diff = this.endDate - Date.now();
  		}, 1000);
	}
 
 	// 销毁组件时清除定时器
 	ngOnDestroy() {
  		if (this.timer) {
   			clearInterval(this.timer);
  		}
 	}


}

